#pragma once
#include "dll_export.h"
#include "Mediator.h"

#if wxCHECK_VERSION(2,9,4)
#include <wx/stc/stc.h>
#define wxScintilla wxStyledTextCtrl
#define wxScintillaEvent wxStyledTextEvent
#else
#include <wx/wxScintilla/wxscintilla.h>
#endif

#include <boost/shared_ptr.hpp>

LUA_DEBUG_BEGIN

class OneVariableWatchView;
class SourceView;

class SourceViewPage : public wxScintilla
{
    DECLARE_EVENT_TABLE();

    SourceView *m_parent;
    bool m_initialized;
    bool m_isModified;

    std::string m_key;
    wxString m_title;
    bool m_hasPath;
    int m_currentLine;
    int m_markedLine;

    OneVariableWatchView *m_watch;

    Mediator_ptr m_mediator;

public:
    explicit SourceViewPage(Mediator_ptr mediator,SourceView *parent);

    virtual ~SourceViewPage();

public:
    /// Get the source key.
    const std::string &GetKey() const {
        return m_key;
    }

    /// Get the source title.
    const wxString &GetTitle() const {
        return m_title;
    }

    /// Initialize this object.
    void Initialize(const Source &source);

    /// Focus the current running line.
    int FocusCurrentLine(int line, bool isCurrentRunning=true);

    void ToggleBreakpointFromLine(int line);

    void ToggleBreakpoint();

    /// Focus the error line.
    void FocusErrorLine(int line);

    /// Change whether this object is enable.
    void ChangeEnable(bool enable);

    /// Save source text.
    void SaveSource();

private:
    void CreateGUIControls();

    /// Fold the source, if any.
    void OnMarginClick(wxScintillaEvent &event);

    /// Save source if 'Ctrl+S' key was pressed.
    void OnKeyDown(wxKeyEvent &event);

    /// Enable or disable the modified mark.
    void ChangeModified(bool modified);

    /// Modified mark may be set, if any.
    void OnModified(wxScintillaEvent &event);

    /// Indent if newline was added.
    void OnCharAdded(wxScintillaEvent &event);

    void CloseWatch();

    void OnHotSpotClick(wxScintillaEvent &event);

    void OnLeftDown(wxMouseEvent &event);

    void OnMotion(wxMouseEvent &event);

    /// Refresh the breakpoint marks.
    void OnChangedBreakpoints(wxDebugEvent &/*event*/);
};

LUA_DEBUG_END
